//
//  ViewController.m
//  文本框交互
//
//  Created by mir_yan on 2018/10/3.
//  Copyright © 2018年 hakeem. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *myField;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    
    self.myField.delegate = self;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark- UITextFieldDelegate
// 即将进入编辑时触发回调
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    
    NSLog(@"textField:%p", textField);
    
    return YES;
}
// 已经编辑
- (void)textFieldDidBeginEditing:(UITextField *)textField {
    
}
// 已经结束编辑回调
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
    return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    
}

- (void)textFieldDidEndEditing:(UITextField *)textField reason:(UITextFieldDidEndEditingReason)reason NS_AVAILABLE_IOS(10_0) {
    
}
// 文本内容变化时回调
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    
    NSLog(@"string:%@", string);
    NSLog(@"range:%@", NSStringFromRange(range));
    
    return YES;
}
// 内容清除时回调
- (BOOL)textFieldShouldClear:(UITextField *)textField {
    return YES;
}
// return键被点击回调
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    return YES;
}

@end
